package bookshop.service.impl;

import java.util.ArrayList;
import java.util.List;

import bookshop.dao.CategoryDao;
import bookshop.dao.DaoFactory;
import bookshop.domain.Category;
import bookshop.service.CategoryService;
import bookshop.service.helper.CategoryQueryHelper;
import bookshop.utils.Page;

public class CategoryServiceImpl implements CategoryService {

	public void createCategory(Category ctg) {
    
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		ctgDao.addCategory(ctg);
	}

	public List<Category> loadall() {
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		return ctgDao.loadall();
	}

	public Category getCategoryById(int ctgId) {
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		return ctgDao.getCategoryById(ctgId);

	}

	public void updateCategory(Category ctg) {
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		ctgDao.update(ctg);
	}
	
	public void removeCtg(Integer ctgId){
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		ctgDao.delete(ctgId);
		
	}

	
	public Page loadCategoryByCondition(CategoryQueryHelper helper, Page page) {
		CategoryDao ctgDao = (CategoryDao) DaoFactory.getDao("categoryDao");
		page.setTotalRecNum(ctgDao.countCategoryByConditon(helper));
		page.setPageContent(ctgDao.getScopedCategorys(helper, page.getStartIndex(), page.getPageSize()));
		
		return page;
	}

	
	

}
